import request from '@/utils/request'

const api = {
  roleList: '/role/list',
  roleAdd: '/role/add',
  roleUpdate: '/role/update',
  roleName: '/role/roleName'
}

export default api

const Map = {
  'descend': 'desc',
  'ascend': 'asc'
}
export function getRoleTable (parameter) {
  return request({
    url: api.roleList,
    method: 'get',
    params: {
      createUser: parameter.createUser || null, // 解决传空字符串的问题(如果是空字符串,不携带这个参数)
      roleName: parameter.roleName,
      createTime: parameter.createTime,
      page: parameter.page || 1,
      pageSize: parameter.pageSize || 10,
      order: Map[parameter.order] || 'desc'
    }
  })
}

export function addRoleTable (parameter) {
  return request({
    url: api.roleAdd,
    method: 'post',
    params: {
      roleName: parameter.roleName,
      description: parameter.description
    }
  })
}

export function updateRoleTable (parameter) {
  return request({
    url: api.roleUpdate,
    method: 'put',
    params: {
      roleName: parameter.roleName,
      id: parameter.id,
      description: parameter.description
    }
  })
}

export function getAllRoleName () {
  return request({
    url: api.roleName,
    method: 'get'
  })
}
